<.header>
  Message <%= @message.id %>
  <:subtitle>This is a message record from your database.</:subtitle>
  <:actions>
    <%= if assigns[:current_user] && @current_user.id == @message.user_id do %>
      <.link navigate={~p"/messages/#{@message}/show/edit"} phx-click={JS.push_focus()}>
        <.button>Edit message</.button>
      </.link>
    <% end %>
  </:actions>
</.header>

<.list>
  <:item title="Content"><%= @message.content %></:item>
  <:item title="Picture"><img src={@message.picture} /></:item>
</.list>

<.back navigate={~p"/messages"}>Back to messages</.back>

<.modal
  :if={@live_action == :edit}
  id="message-modal"
  show
  on_cancel={JS.patch(~p"/messages/#{@message}")}
>
  <.live_component
    module={PicChatWeb.MessageLive.FormComponent}
    id={@message.id}
    title={@page_title}
    action={@live_action}
    message={@message}
    patch={~p"/messages/#{@message}"}
    current_user={@current_user}
  />
</.modal>
